const Router = require('koa-router');
const router = new Router();
const tool = require('../../tools/tool')
const {db, QueryTypes} = require("../../models/db");

router.post('/menu/getMenuV5', async ctx => {
    let user = ctx.user;
    let tenantId = user.tenantId;
    let sql = `select * from menu_v5`
    let ret = await db.query(sql, {type: QueryTypes.SELECT})
    return ctx.suc('', ret)
})

router.post('/menu/getTenantMenu', async ctx => {
    let user = ctx.user;
    let tenantId = ctx.request.body.tenantId;
    let sql = `select * from tenant_menu where tenantId=${tenantId}`
    let ret = await db.query(sql, {type: QueryTypes.SELECT})
    return ctx.suc('', ret)
})
router.post('/menu/used', async ctx => {
    let user = ctx.user;
    let tenantId = ctx.request.body.tenantId;
    let sql = `select top 20 a.* from menu_v5 a inner join menu_used b on a.id=b.menuId and b.adminId=${user.id} order by b.times desc`
    let ret = await db.query(sql, {type: QueryTypes.SELECT})
    return ctx.suc('', ret)
})
module.exports = router;
